// pages/person/evaluate.js
const app = getApp()
var wh = require("../../utils/wh.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    istrue: true,
    list: [],
    page: 1,
    page_size: 5,
    no_data: 0,
    onearth: false, // 是否已经到达底部
    have: true, 
  },
  nav() {
    let istrue = this.data.istrue
    this.setData({
      istrue: !istrue,
      page: 1,
      page_size: 5,
      no_data: 0,
      onearth: false,
      have: true, 
      list: [],
    })
    if (!istrue) {
      let img = ''
      this.mylist(img)
    } else {
      let img = '1'
      this.mylist(img)
    }
  },
  
  // 获取我的评价
  mylist(img){
    let that = this;
    let page_size = this.data.page_size,
      no_data = this.data.no_data,
      page = this.data.page;
    if (no_data == 0) {
      wh.Post('/api/mall.comment/mylist', {
        page: page,
        page_num: page_size,
        img: img
      }, function (res) {
        console.log('我的评价', res)
        let shop = that.data.list.concat(res),
          count = res.length;
        console.log(res)
        if (page_size > count) {
          that.data.no_data = 1;
          if (shop.length > 3) {
            that.setData({
              onearth: true
            })
          }
        }
        that.setData({
          list: shop
        })
        if (that.data.list.length == 0) {
          that.setData({
            have: false,
          });
        } else {
          that.setData({
            have: true,
          });
        }
      })
    }
  },
  //删除评价 
  del_comment: function (e) {
    console.log(e.currentTarget.dataset.id)
    let that = this,
      id = e.currentTarget.dataset.id,
      list = this.data.list,
      inx = e.currentTarget.dataset.inx;
    wh.Post('/api/mall.comment/del_comment', {
      comment_id: id
    }, function (res) {
      wx.showToast({
        title: '删除成功',
      });
      let arr = that.data.list;
      arr.splice(inx, 1)
      that.setData({
        list: arr
      });
    });
  },
  tobackhander(e){
    wx.navigateTo({
      url: 'backhander?order_id=' + e.currentTarget.dataset.order_id + '&comment_id=' + e.currentTarget.dataset.comment_id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let img = '';
    this.mylist(img)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let no_data = this.data.no_data,
      page = this.data.page,
      istrue = this.data.istrue,
      page_size = this.data.page_size;
    if (no_data == 0) {
      this.data.page = page + 1;
      if (!istrue) {
        let img = ''
        this.mylist(img)
      } else {
        let img = '1'
        this.mylist(img)
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})